import 'package:flutter/material.dart';

//顶部导航栏
class HomeNav extends StatelessWidget {
  HomeNav({super.key});
  List navs = [
    {'title': '我的房屋', 'icon': 'assets/images/house_nav_icon@2x.png'},
    {'title': '我的报修', 'icon': 'assets/images/repair_nav_icon@2x.png'},
    {'title': '访客登记', 'icon': 'assets/images/visitor_nav_icon@2x.png'}
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 70,
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(left: 10, right: 10),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: GridView.builder(
        //禁止滚动
        physics: const NeverScrollableScrollPhysics(),
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            childAspectRatio: 1,
            mainAxisSpacing: 10,
            crossAxisSpacing: 10),
        itemBuilder: (BuildContext context, int index) {
          return Container(
              child: GestureDetector(
            child: Column(
              children: [
                Image.asset(
                  navs[index]['icon'],
                  width: 30,
                ),
                Text(
                  navs[index]['title'],
                  style: const TextStyle(fontSize: 12),
                ),
              ],
            ),
            //点击事件
            onTap: () {
              print('点击了${navs[index]['title']}');
              if (navs[index]['title'] == '我的房屋') {
                Navigator.pushNamed(context, '/houseList');
              }
            },
          ));
        },
        itemCount: navs.length,
      ),
    );
  }
}
